//右上 居家照护服务机构区域详情
(function () {
    //1.实例化对象
    // var myChart = echarts.init(document.querySelector('#detail_statistics'));
    //2.指定配置项和数据

    $.ajax({
        url: "../statistics/kkfw",
        type: "post",
        dataType: "json",
        success: function (data) {
            var myChart = echarts.init(document.querySelector('#detail_statistics'));
            let datas=[];
            let center=[
                ["30%","45%"],
                ["58%","45%"],
                ["85%","45%"],
                ["43%","75%"],
                ["70%","75%"],
            ];
            for (let i in data){
                datas.push(                    {
                        name: data[i].jdfwApartment,
                        type: 'pie',
                        radius:['17%','34%'],
                        center:center[i],
                        //图形标签
                        label:{
                            position:'center',
                            show:true,
                            overflow : 'break',

                            color :"rgba(255,255,255,0.7)",
                            fontSize: fontSize(0.12),
                        },

                        //链接图形和文字的线
                        data: [
                            {value: data[i].value, name:data[i].name},

                        ],

                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)',
                                formatter:function(val){   //让series 中的文字进行换行
                                    return val.name.split("-").join("\n");},
                            }
                        }

                    }
                )
            }

            var option = {

                tooltip: {
                    trigger: 'item',
                    confine: true,
                },
                legend: {
                    //修改图例的位置
                    orient: 'vertical',
                    left: 'left',
                    //修改小图标的大小
                    textStyle:{
                        color :"rgba(255,255,255,0.7)",
                        fontSize: fontSize(0.12),
                    },
                    itemWidth:10,
                    itemHeight:10,
                    left: 'left',
                    bottom:"0%"
                },
                series: datas
            };
//3.把配置项给实例对象
            myChart.setOption(option);
            //4、让图表自适应屏幕
            window.addEventListener("resize",function () {
                    myChart.resize();
                }
            )
        }
    })

})();

function placeholderPic(){
    var w = document.documentElement.offsetWidth;
    document.documentElement.style.fontSize=w/120+'px';
}
placeholderPic();
window.onresize=function(){
    placeholderPic();
}


function fontSize(res){
    let docEl = document.documentElement,
        clientWidth = window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
    if (!clientWidth) return;
    let fontSize = 100 * (clientWidth / 1920);
    return res*fontSize;
}